//
//  PublicClass.m
//  phmall
//
//  Created by admin on 2017/10/24.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "PublicClass.h"

@implementation PublicClass
#pragma mark - 计算商铺信用等级
+(NSMutableDictionary *)countLevel:(int)level{
    int num=0;
    ShopLevelIcon icon=ShopLevelIconGrayHeart;
    NSMutableDictionary *levelDict=[[NSMutableDictionary alloc]init];
    if(level>0&&level<=10){
        num=1;
        icon=ShopLevelIconGrayHeart;
    }
    if(level>10&&level<=40){
        num=2;
        icon=ShopLevelIconIconRedHeart;
    }
    if(level>40&&level<=90){
        num=3;
        icon=ShopLevelIconIconRedHeart;
    }
    if(level>90&&level<=150){
        num=4;
        icon=ShopLevelIconIconRedHeart;
    }
    if(level>150&&level<=250){
        num=5;
        icon=ShopLevelIconIconRedHeart;
    }
    
    if(level>250&&level<=500){
        num=1;
        icon=ShopLevelIconIconDiamond;
    }
    if(level>500&&level<=1000){
        num=2;
        icon=ShopLevelIconIconDiamond;
    }
    if(level>1000&&level<=2000){
        num=3;
        icon=ShopLevelIconIconDiamond;
    }
    if(level>2000&&level<=5000){
        num=4;
        icon=ShopLevelIconIconDiamond;
    }
    if(level>5000&&level<=10000){
        num=5;
        icon=ShopLevelIconIconDiamond;
    }
    
    if(level>10000&&level<=20000){
        num=1;
        icon=ShopLevelIconIconSilverCrown;
    }
    if(level>20000&&level<=50000){
        num=2;
        icon=ShopLevelIconIconSilverCrown;
    }
    if(level>50000&&level<=100000){
        num=3;
        icon=ShopLevelIconIconSilverCrown;
    }
    if(level>100000&&level<=200000){
        num=4;
        icon=ShopLevelIconIconSilverCrown;
    }
    if(level>200000&&level<=500000){
        num=5;
        icon=ShopLevelIconIconSilverCrown;
    }
    
    if(level>500000&&level<=1000000){
        num=1;
        icon=ShopLevelIconIconGoldenCrown;
    }
    if(level>1000000&&level<=2000000){
        num=2;
        icon=ShopLevelIconIconGoldenCrown;
    }
    if(level>2000000&&level<=5000000){
        num=3;
        icon=ShopLevelIconIconGoldenCrown;
    }
    if(level>5000000&&level<=10000000){
        num=4;
        icon=ShopLevelIconIconGoldenCrown;
    }
    if(level>10000000){
        num=5;
        icon=ShopLevelIconIconGoldenCrown;
    }
    
    [levelDict setObject:[NSString stringWithFormat:@"%d",num] forKey:@"num"];
    [levelDict setObject:[NSString stringWithFormat:@"%lu",(unsigned long)icon] forKey:@"icon"];
    return levelDict;
}
+(void)ProgressHUDModeText:(NSString *)text andTime:(NSTimeInterval )time{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow  animated:YES];
    hud.bezelView.color=[UIColor blackColor];
    hud.userInteractionEnabled = NO;
    hud.mode = MBProgressHUDModeText;
    hud.detailsLabel.text = text;
    hud.detailsLabel.font=[UIFont systemFontOfSize:15];
    hud.detailsLabel.textColor=[UIColor groupTableViewBackgroundColor];
    hud.minShowTime = time;
    [hud hideAnimated:YES];
}

+ (NSString *)timeWithTimeIntervalString:(NSString *)timeString
{
    // 格式化时间
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    formatter.timeZone = [NSTimeZone timeZoneWithName:@"shanghai"];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
    
    // 毫秒值转化为秒
    NSDate* date = [NSDate dateWithTimeIntervalSince1970:[timeString doubleValue]];
    NSString* dateString = [formatter stringFromDate:date];
    return dateString;
}
@end
